package com.wd.live.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.wd.live.base.BaseViewModel;
import com.wd.live.bean.WxBean;
import com.wd.live.model.HttpUtils;
import com.wd.live.model.SpUtils;


import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class WxModel extends BaseViewModel {
    public WxModel(@NonNull Application application) {
        super(application);
    }
    MutableLiveData<WxBean> WxData=new MutableLiveData<>();

    public MutableLiveData<WxBean> getWxData(String code, String contentType) {
        String code1 = SpUtils.getString("code","");
        HttpUtils.getHttpUtils().getApi().wxLogin(code1,"application/x-www-form-urlencoded")
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<WxBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(WxBean value) {
                    WxData.postValue(value);
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
        return WxData;
    }

}
